<template>
  <div class="login-container">
    <div class="trace">
      <div class="trace-item" :class="{thiscome:show}" @click="show=true">登录</div>
      <div class="trace-item" :class="{thiscome:show==false}" @click="show=false">注册</div>
    </div>
    <div class="login-box"  v-show="show">
      <div class="text-center avatar-box">
        <!-- <img src="../assets/logo.png" class="img-thumbnail avatar" alt="" /> -->
      </div>
        <div class="name">
          <label for="username">登录名称</label>
          <input
         
             id="username"
             class="input"
            placeholder="请输入登录名称"
            autocomplete="off"
            v-model.trim="username"
          />
        </div>
        <div class="pw">
          <label for="password">登录密码</label>
          <input
            id="password"
              class="input"
            placeholder="请输入登录密码"
            v-model.trim="password"
          />
        </div>
        <div class="btn ">
          <button class="btn-item"  @click="reset">重置</button>
          <button class="btn-item"  @click="login(username)">登录</button>
        </div>
    </div>
    <div class="login-box"  v-show="show==false">
      <div class="text-center avatar-box">
        <!-- <img src="../assets/logo.png" class="img-thumbnail avatar" alt="" /> -->
      </div>
      
        <div class="name">
          <label for="username">登录名称</label>
          <input
             id="username"
             class="input"
            placeholder="请输入登录名称"
            autocomplete="off"
            v-model.trim="username"
          />
        </div>
        <div class="pw">
          <label for="password">登录密码</label>
          <input
            id="password"
              class="input"
            placeholder="请输入登录密码"
            v-model.trim="password"
          />
        </div>
        <div class="btn">
          <button class="btn-item" @click="reset">重置</button>
          <button class="btn-item" @click="register(username)">注册</button>
        </div>
      
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoginView',
  data() {
    return {
      show:true,
      username: '',
      password: ''
    }
  },
  created(){
      localStorage.userList = JSON.stringify(
          { 
            username:'123',
            password:'123'
          }
        );     
  },
  methods: {
    reset() {
      this.username = ''
      this.password = ''
    },
    register(username){
      if (username == '123') {
        this.show=true
      }else{
        alert('用户不允许进入')
      }
    },
    login(username) {
      if (username == '123') {
        localStorage.setItem('token', 'cvwgwbwrg')
        localStorage.setItem('user',username)
        this.$router.push(`/user/${username}`)
      } else {
        localStorage.removeItem('token')
        alert('用户名或密码输入错误，请重试')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  background-color: white;
  height: 100vh;
  width: 100vw;
  position: fixed;
  top: 0;
  z-index: 999;
  .trace{
    width: 400px;
    height: 50px;
    line-height: 50px;
    display: flex;
    justify-content: space-between;
    position: relative;
    top: 32.5%;
    left:13%;

    .trace-item{
      flex: 1;
      text-align: center;
      font-size: 18px;
      color: aliceblue;
      background-color: rgb(52, 50, 50);
      border: 1px solid rgb(94, 91, 91);
       &.thiscome{
      background-color: rgb(230, 80, 80);
      color: black;
    }
    }
  }
  .login-box {
    width: 400px;
    height: 250px;
    background-color: orange;
    border-radius: 3px;
    position: relative;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
   
    .name{
      display: flex;
      position: absolute;
      left: 45%;
      top: 50%;
      transform: translate3d(-40%,-150%,0);
    }
    .pw{
      display: flex;
      position: absolute;
      left: 45%;
      top: 50%;
      transform: translate3d(-40%,-10%,0);
    }
    label{
      width: 60px;
      height: 35px;
      line-height: 35px;
      font-size: 12px;
    }
    .input{
      width: 150px;
      height: 35px;
      outline: none;
      border-radius: 10px;
      border: 0;
    }
    .btn{
      display: flex;
      justify-content: space-around;
      width: 80%;
       position: absolute;
      left: 10%;
      top: 75%;
      .btn-item{
        flex: 0 0 20%;
        color: white;
        background-color: rgb(94, 72, 31);
        border-radius: 10px;
      }
    }
  }
}

</style>

